#include <stdio.h>
#include <string.h>

int min(int a,int b){
	return a<b ? a : b;
}

int max(int a,int b){
	return a>b ? a : b;
}

int cmp(char A[],char B[]){
	int i,j;
	for (i = 0; i<min(strlen(A),strlen(B));i++)
		if (A[i] != B[i])	return A[i] > B[i];
	return strlen(A)>strlen(B);
}

void swap(char **A,char **B){
	char *ch = *A;
	*A = *B;
	*B = ch;
}

int main(){
	char str[200][200];
	char *c[200];
	int i = 0,j,k,l,n,m;
	char A;
	while (gets(str[i]) && strcmp(str[i],"#"))i++;
	for (j = 0; j<i; j++)
		c[j] = &str[j];
	for (j = 0;j<i-1; j++)
		for (k = j+1; k<i; k++)
			if (cmp(*(c+j),*(c+k))){
				swap(&c[j],&c[k]);
			}
	for (j = 0; j<i; j++)
		printf("%s\n",*(c+j)); 
	return 0;
}